<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script src="<c:url value='/static/jquery/jquery-1.9.1.min.js'/>" type="text/javascript"></script>
<script type="text/javascript" src="<c:url value='/static/themes/js/jquery.datatables.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/static/datetimepicker/js/bootstrap-datetimepicker.js'/>"charset="UTF-8"></script>	
<title>申述管理</title>
</head>
<body>
	<div class="panel panel-default bk-bg-white">
		<div class="panel-body">
		<form class="form-horizontal">
			<div class="row">
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">发起人：</label> 
					<div class="col-sm-8">
						<select id="userRoles" class="form-control">
							<option value="">全部</option>
							<option value="0">买手</option>
							<option value="1">商家</option>
						</select>
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">申诉状态：</label> 
					<div class="col-sm-8">
						<select id="appealsStatus" class="form-control">
							<option selected="selected" value="">全部</option>
							<option  value="0">等待处理</option>
							<option value="1">协商中</option>
							<option  value="2">平台介入</option>
							<option value="3">已完结</option>
						</select>
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">订单编号：</label> 
					<div class="col-sm-8">
						<input type="text" class="form-control" id="orderId"  placeholder="订单编号">
					</div>
				</div>
			</div>
			<div class="row">
				
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">撤销订单：</label> 
					<div class="col-sm-8">
   						<select id="undoStatus" class="form-control">
							<option value="">全部</option>
							<option value="0">未申请</option>
							<option value="1">已申请</option>
							<option value="2">已撤销</option>
						</select>
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">申诉时间：</label> 
					<div class="col-sm-8">
   						<input class="input-append date form_datetime form-control" id="startAppealsTime" >
						    <span class="add-on"><i class="icon-remove"></i></span>
						    <span class="add-on"><i class="icon-calendar"></i></span>
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-1 control-label">-</label>
					<div class="col-sm-8">
   						<input class="input-append date form_datetime form-control" id="endAppealsTime" >
						    <span class="add-on"><i class="icon-remove"></i></span>
						    <span class="add-on"><i class="icon-calendar"></i></span>
					</div>
				</div>
				
			</div>
			<div class="row">
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">平台介入：</label> 
					<div class="col-sm-8">
						<select id="platformIntervention" class="form-control">
							<option value="">全部</option>
							<option value="0">已申请</option>
							<option value="1">未申请</option>
						</select>
						
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">申诉类型：</label> 
					<div class="col-sm-8">
						<select id="appealProblemTypeID" class="form-control">
							<option value="">全部</option>
							<option value="1">平台问题</option>
							<option value="2">买手问题</option>
							<option value="3">商家问题</option>
						</select>
						
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">平台处理状态：</label> 
					<div class="col-sm-8">
						<select id="platformProcessingStatus" class="form-control">
							<option value="">全部</option>
							<option value="0">无</option>
							<option value="1">继续跟进</option>
							<option value="2">已完结</option>
						</select>
						
					</div>
				</div>
				
			</div>
			
			<div class="form-group col-sm-12" style="padding-bottom: 15px; text-align: center;">
					<button id="search" type="button" class="btn btn-primary glyphicon glyphicon-search"> 搜索</button>
			</div>
		</form>	
		</div>
	</div>
	<!-- panel-body -->
	<div id="message"></div>
	<!-- panel -->
	<div class="panel panel-default">
		<div class="panel-body">
			<div class="table-responsive">
				<div id="table1_wrapper" class="dataTables_wrapper no-footer">
					<table id="table" class="display nowrap" cellspacing="0" width="100%">
						<thead>
							<tr role="row">
								<th>发起人</th>
								<th>发起人生财ID</th>
								<th>被申诉人生财ID</th>
								<th>申诉时间</th>
								<th>订单编号</th>
								<th>申诉类型</th>
								<th>申诉进程</th>
								<th>撤销订单</th>
								<th>平台介入</th>
								<th>申诉状态</th>
								<th>平台处理状态</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
		<div id="page">
			
		</div>
	</div>

	<script type="text/javascript">
	
	
	$(function($) {
		//日期控件
		$('#startAppealsTime').datetimepicker({
			language : 'zh-CN',
			format : 'yyyy-mm-dd hh:ii', 
			autoclose : true,
			todayBtn : true,
			minuteStep : 10
		}).on('changeDate', function (ev) {
			var starttime = $(this).val();
			$('#endAppealsTime').datetimepicker('setStartDate',starttime);
            $(this).datetimepicker('hide');  
        });
		
		$('#endAppealsTime').datetimepicker({
			language : 'zh-CN',
			format : 'yyyy-mm-dd hh:ii',
			autoclose : true,
			todayBtn : true,
			minuteStep : 10
		}).on('changeDate', function (ev) {
			var time = $(this).val();
			$('#startAppealsTime').datetimepicker('setEndDate',time);
            $(this).datetimepicker('hide');  
        });
		
		function doSearch(){
			var table = $('#table').DataTable({
		        "processing": true,
		        "serverSide": true,
		        "bLengthChange": false,
		        "bFilter": false,
		        "bSort":false,
		        "bDestroy":true, 
		        "scrollX" : true,
		        "language": {
		            "url": path+"/static/language_datatables.json"
		        },
		        "ajax": {
		            "url": path+"/complaints/getList",
		            "type": "POST",
		            "data":{
		                	"userRoles": $('#userRoles').val(),
		                    "startAppealsTime": $('#startAppealsTime').val(),
		                    "endAppealsTime": $('#endAppealsTime').val(),
		                    "orderId": $('#orderId').val(),
		                    "appealsStatus": $('#appealsStatus').val(),
		                    "platformProcessingStatus": $('#platformProcessingStatus').val(),
		                    "undoStatus": $('#undoStatus').val(),
		                    "platformIntervention":$("#platformIntervention").val(),
		                    "appealProblemTypeID": $('#appealProblemTypeID').val()
		            	}
		        },
		        "columns": [
		            { "data": "userroles" ,"width": "10%"},
		            { "data": "sponsor" ,"width": "10%"},
		            { "data": "otherusers","width": "10%" },
		            { "data": "appealstime" ,"width": "10%"},
		            { "data": "orderid" ,"width": "10%"},
		            { "data": "appealproblemname" ,"width": "10%"},
		            { "data": "sponsor","width": "10%"},
		            { "data": "undostatus","width": "10%"},
		            { "data": "platformintervention","width": "10%"},
		            { "data": "appealsstatus","width": "10%"},
		            { "data": "complaintsid","width": "10%"},
		        ],
		        "columnDefs": [
                    {
	                     "render": function ( data, type, row ) {
	                   		 var href="";
	               			 if(row.userroles=="0"){
	               				 //发起申述人角色是买手
	               				 href="<a href='<c:url value='/user/buyerUserDetail?id="+data+"'/>'>"+data+"</href>";	 
	               			 }else if(row.userroles=="1"){
	               				 href="<a href='<c:url value='/user/businessUserDetail?id="+data+"'/>'>"+data+"</href>";
	               			 }
	                   		 return href;
	                     },
	                     "targets": 1
                   },
  	               {
	                     "render": function ( data, type, row ) {
	                    	 var href="";
	               			 if(row.otherroles=="0"){
	               				href="<a href='<c:url value='/user/buyerUserDetail?id="+data+"'/>'>"+data+"</href>";
	               			 }else if(row.userroles=="1"){
	               				href="<a href='<c:url value='/user/businessUserDetail?id="+data+"'/>'>"+data+"</href>";
	               			 }
	                   		 return href;
	                     },
	                     "targets": 2
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	 return dateTimeFormatter(data);
	                     },
	                     "targets": 3
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	 if(data=="0"){
	                    		 return '买手';
	                    	 }else  if(data=="1"){
	                    		return '商家';
	                    	 }else{return "";}
	                     },
	                     "targets": 0
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	 if(row.undostatus!="2"){
	                    		 var href="<a href='<c:url value='/order/detail/"+data+"'/>'>"+data+"</href>";
	                    		 return href;
	                    	 }
	                    	 return data;
	                     },
	                     "targets": 4
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	 if(data=="1"){
	                    		 return "平台问题";
	                    	 }else  if(data=="2"){
	                    		 return "买手问题";
	                    	 }else  if(data=="3"){
	                    		 return "商家问题";
	                    	 }else{return "";}
	                     },
	                     "targets": 5
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	 return "<a href='<c:url value='/complaints/detail?complaintsId="+row.complaintsid+"'/>'>查看进程</a>";
	                     },
	                     "targets": 6
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	 if(data=="0"){
	                    		 return "未申请";
	                    	 }else  if(data=="1"){
	                    		 return "已申请";
	                    	 }else  if(data=="2"){
	                    		 return "已撤销";
	                    	 }else{return "";}
	                     },
	                     "targets": 7
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	 if(data=="0"){
	                    		 return "已申请";
	                    	 }else  if(data=="1"){
	                    		 return "未申请";
	                    	 }else{return "";}
	                     },
	                     "targets": 8
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	 if(data=="0"){
	                    		 return "等待处理";
	                    	 }else  if(data=="1"){
	                    		 return "协商中";
	                    	 } else if(data=="2"){return "平台介入";}
	                    	 else if(data=='3'){return "已完结";}
	                    	 return "";
	                     },
	                     "targets": 9
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	if(row.appealsstatus!='3'){
	                    		var ret= '<button class="btn btn-warning changeStatus" status="3" time="'+row.appealstime+'" complaintsId="'+row.complaintsid+'" orderId="'+row.orderid+'" sponsor="'+row.sponsor+'">完结</button>';
		                     	return ret;
	                    	}else{
	                    		return "";
	                    	}
	                    	/*  var ret="<select class='changeStatus' time='"+row.appealstime+"' complaintsId='"+row.complaintsid+"' orderId='"+row.orderid+"' sponsor='"+row.sponsor+"'>";
		                    	 ret+="<option value='0' "+(row.platformprocessingstatus=='0'?'selected':'')+">无</option>";
		                    	 ret+="<option value='1' "+(row.platformprocessingstatus=='1'?'selected':'')+">继续跟进</option>";
		                    	 ret+="<option value='2' "+(row.platformprocessingstatus=='2'?'selected':'')+">已完结</option>";
	                    	 ret+="</select>";
	                    	 return ret; */
	                     },
	                     "targets": 10
	                 },
	             ]

		    }); 
		};
		doSearch();
		
		//查询事件
		$('#search').click(function(){
			doSearch();
		});
		
		
		bandclick();
		function bandclick(){
			$('body').on("click",'.changeStatus',function(){
				_t = $(this);
				console.log(_t);
				var complaintsId=_t.attr("complaintsId");
				var status=_t.attr("status");
				updateStauts(complaintsId,status);
			});
		}
		
		
		function updateStauts(complaintsId,status){
			$.blockUI({ message: '加载中...' });
			$.ajax({
				type : "post",
				url : path  + "/complaints/updateStauts",
				cache : false,
				data : {
					status:status,
					complaintsId:complaintsId,
					_t : new Date().getTime()
				},
				dataType : "json",
				success : function(data) {
					showmessage(data.msg);
					if (data.success) {
						doSearch();
					}
					$.unblockUI();
				}
			});
		}
		
	});
	
	
	
	//显示消息
	function showmessage(msg,callback){
		$('#message').ucMessage({
			msg:msg,
			callback:callback
		});
	}
	 
	</script>
</body>
</html>